@extends('admin.common.base-master')

@section('html-head')
    <style type="text/css">
        .divcss5_list_title{background:#eeeeee; border:1px solid #cccccc; padding:1em;}
        .divcss5_list_content{padding:1em;}
        #tinybox{position:absolute; display:none; padding:10px; background:url('{{url('images/preload.gif')}}') no-repeat 50% 50%;  z-index:2000;}
        #tinymask{position:absolute; display:none; top:0; left:0; height:100%; width:100%; background:#000000; z-index:1500;}
        #tinycontent{background:#ffffff; font-size:1.1em;}

        #n{margin:10px auto; width:920px; border:1px solid #CCC;font-size:12px; line-height:30px;}
        #n a{ padding:0 4px; color:#333}
        .sx{padding: 10px}
        .sx-btn{width: 64px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
    </style>
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">论坛讨论列表</a>
        </div>


        <div class="filter-box clearfix">
            <div class="fr" style="margin-top: 10px;">
                <a class="addBtn" href="{{route('Admin.Home.forumDiscussSet')}}?forum_id={{$forum->id}}">新增</a>
            </div>
        </div>

        <div>讨论内容：{{$forum->title}}</div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户头像</th>
                    <th>评论用户</th>
                    <th>被评论的用户</th>
                    <th>回复内容</th>
                    <th>评论时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($forumDiscussList) > 0)
                    @foreach($forumDiscussList as $forumDiscuss)
                        <tr id="plan_{{$forumDiscuss->id}}">
                            <td>{{$forumDiscuss->id}}</td>

                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    <img src="{{$forumDiscuss->photo_url}} " alt="">
                                </span>
                            </td>

{{--
                            <td>{{$forumDiscuss->from_user_info->nickname}}</td>
--}}

                            <td>{{$forumDiscuss->from_uesr_nickname}}</td>



                        {{--    <td>@if(!is_null($forumDiscuss->from_user_info->nickname)){{$forumDiscuss->from_user_info->nickname}}@else{{$forumDiscuss->nick_name}} @endif</td>--}}
                            <td>@if(!is_null($forumDiscuss->to_user_info)){{$forumDiscuss->to_user_info->nickname}}@else 无 @endif</td>
                            <td>{{$forumDiscuss->content}}</td>
                            <td>{{$forumDiscuss->created_at}}</td>
                            <td><a href="javascript:void(0);" class="del" data-id="{{$forumDiscuss->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                <tfoot class="order-gl">

                </tfoot>
            </table>
        </div>
    </div>




    <script>

        function upPop(obj1,obj2,obj3,obj4,obj5,obj6){
            $('#forum_discuss_id').val(obj1);
            $('#forum_id').val(obj4);
            $('#discuss').val(obj5);
            $('#nick_name').val(obj6);
            $('#img_id').val(obj2);
            $('#img_show').attr('src',obj3);
            $('.upPop-box').upPop();

        }




            $(function(){
                $(document).on('click', '#subThisForm', function () {
                    var nick_name = $('#nick_name').val();
                    var discuss  = $('#discuss').val();
                    var forum_discuss_id = $('#forum_discuss_id').val();
                    var img_id = $('#img_id').val();
                    var forum_id = $('#forum_id').val();

                    $.ajax({
                        url: '{{route("Api.Admin.Forum.setForumDiscuss")}}',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            nick_name:nick_name,
                            content:discuss,
                            forum_discuss_id:forum_discuss_id,
                            photo_id:img_id,
                            forum_id:forum_id,
                        },
                        success: function (obj) {
                            if (obj.level == "success") {
                                noty({
                                    text: obj.message, type: obj.level, timeout: 600,
                                    callback: {
                                        afterClose:function(){
                                            window.location.reload();
                                        }
                                    }
                                });
                            } else if (obj.level == "error") {
                                noty({text: obj.message, type: obj.level, timeout: 600});
                            }

                        },
                        error: function (obj) {
                            console.log(obj);
                        }
                    });
                });

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '该讨论内容即将被删除，你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.Forum.delForumDiscuss')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#plan_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });
            });
        });
    </script>
@endsection